package com.ruoyi.web.controller.shop;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.shop.domain.Promotional;
import com.ruoyi.shop.service.IPromotionalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 宣传主图Controller
 * 
 * @author ruoyi
 * @date 2025-10-30
 */
@RestController
@RequestMapping("/shop/promotional")
public class PromotionalController extends BaseController
{
    @Autowired
    private IPromotionalService promotionalService;

    /**
     * 查询宣传主图列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Promotional promotional)
    {
        startPage();
        List<Promotional> list = promotionalService.selectPromotionalList(promotional);
        return getDataTable(list);
    }

    /**
     * 导出宣传主图列表
     */
    @Log(title = "宣传主图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Promotional promotional)
    {
        List<Promotional> list = promotionalService.selectPromotionalList(promotional);
        ExcelUtil<Promotional> util = new ExcelUtil<Promotional>(Promotional.class);
        util.exportExcel(response, list, "宣传主图数据");
    }

    /**
     * 获取宣传主图详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(promotionalService.selectPromotionalById(id));
    }

    /**
     * 新增宣传主图
     */
    @Log(title = "宣传主图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Promotional promotional)
    {
        return toAjax(promotionalService.insertPromotional(promotional));
    }

    /**
     * 修改宣传主图
     */
    @PreAuthorize("@ss.hasPermi('shop:promotional:edit')")
    @Log(title = "宣传主图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Promotional promotional)
    {
        return toAjax(promotionalService.updatePromotional(promotional));
    }

    /**
     * 删除宣传主图
     */
    @PreAuthorize("@ss.hasPermi('shop:promotional:remove')")
    @Log(title = "宣传主图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(promotionalService.deletePromotionalByIds(ids));
    }
}
